﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace QuanLyBus.Model
{
    using System.Data.Linq;
    using System.Data.Linq.Mapping;
    using System.Data;
    using System.Collections.Generic;
    using System.Reflection;
    using System.Linq;
    using System.Linq.Expressions;
    using System.ComponentModel;
    using System;


    [global::System.Data.Linq.Mapping.DatabaseAttribute(Name = "QL_Tuyen")]
    public partial class QL_TuyenDataContext : System.Data.Linq.DataContext
    {

        private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();

        #region Extensibility Method Definitions
        partial void OnCreated();
        partial void Insertds_tram(ds_tram instance);
        partial void Updateds_tram(ds_tram instance);
        partial void Deleteds_tram(ds_tram instance);
        partial void Insertds_tuyen(ds_tuyen instance);
        partial void Updateds_tuyen(ds_tuyen instance);
        partial void Deleteds_tuyen(ds_tuyen instance);
        partial void Inserttram_thuoc_tuyen(tram_thuoc_tuyen instance);
        partial void Updatetram_thuoc_tuyen(tram_thuoc_tuyen instance);
        partial void Deletetram_thuoc_tuyen(tram_thuoc_tuyen instance);
        #endregion

       
        public QL_TuyenDataContext(string connection) :
            base(connection, mappingSource)
        {
            OnCreated();
        }


        public QL_TuyenDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
            base(connection, mappingSource)
        {
            OnCreated();
        }

       

        public System.Data.Linq.Table<ds_tram> ds_trams
        {
            get
            {
                return this.GetTable<ds_tram>();
            }
        }

        public System.Data.Linq.Table<ds_tuyen> ds_tuyens
        {
            get
            {
                return this.GetTable<ds_tuyen>();
            }
        }

        public System.Data.Linq.Table<tram_thuoc_tuyen> tram_thuoc_tuyens
        {
            get
            {
                return this.GetTable<tram_thuoc_tuyen>();
            }
        }
    }

    [global::System.Data.Linq.Mapping.TableAttribute]
    public partial class ds_tram : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _id_tram;

        private string _so_nha;

        private string _duong;

        private string _quan;

        private EntitySet<tram_thuoc_tuyen> _tram_thuoc_tuyens;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void Onid_tramChanging(int value);
        partial void Onid_tramChanged();
        partial void Onso_nhaChanging(string value);
        partial void Onso_nhaChanged();
        partial void OnduongChanging(string value);
        partial void OnduongChanged();
        partial void OnquanChanging(string value);
        partial void OnquanChanged();
        #endregion

        public ds_tram()
        {
            this._tram_thuoc_tuyens = new EntitySet<tram_thuoc_tuyen>(new Action<tram_thuoc_tuyen>(this.attach_tram_thuoc_tuyens), new Action<tram_thuoc_tuyen>(this.detach_tram_thuoc_tuyens));
            OnCreated();
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_id_tram", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int id_tram
        {
            get
            {
                return this._id_tram;
            }
            set
            {
                if ((this._id_tram != value))
                {
                    this.Onid_tramChanging(value);
                    this.SendPropertyChanging();
                    this._id_tram = value;
                    this.SendPropertyChanged("id_tram");
                    this.Onid_tramChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_so_nha")]
        public string so_nha
        {
            get
            {
                return this._so_nha;
            }
            set
            {
                if ((this._so_nha != value))
                {
                    this.Onso_nhaChanging(value);
                    this.SendPropertyChanging();
                    this._so_nha = value;
                    this.SendPropertyChanged("so_nha");
                    this.Onso_nhaChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_duong")]
        public string duong
        {
            get
            {
                return this._duong;
            }
            set
            {
                if ((this._duong != value))
                {
                    this.OnduongChanging(value);
                    this.SendPropertyChanging();
                    this._duong = value;
                    this.SendPropertyChanged("duong");
                    this.OnduongChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_quan")]
        public string quan
        {
            get
            {
                return this._quan;
            }
            set
            {
                if ((this._quan != value))
                {
                    this.OnquanChanging(value);
                    this.SendPropertyChanging();
                    this._quan = value;
                    this.SendPropertyChanged("quan");
                    this.OnquanChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.AssociationAttribute(Name = "ds_tram_tram_thuoc_tuyen", Storage = "_tram_thuoc_tuyens", ThisKey = "id_tram", OtherKey = "id_tram")]
        public EntitySet<tram_thuoc_tuyen> tram_thuoc_tuyens
        {
            get
            {
                return this._tram_thuoc_tuyens;
            }
            set
            {
                this._tram_thuoc_tuyens.Assign(value);
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void attach_tram_thuoc_tuyens(tram_thuoc_tuyen entity)
        {
            this.SendPropertyChanging();
            entity.ds_tram = this;
        }

        private void detach_tram_thuoc_tuyens(tram_thuoc_tuyen entity)
        {
            this.SendPropertyChanging();
            entity.ds_tram = null;
        }
    }

    [global::System.Data.Linq.Mapping.TableAttribute]
    public partial class ds_tuyen : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _id_tuyen;

        private string _ten_tuyen_di;

        private string _ten_tuyen_den;

        private EntitySet<tram_thuoc_tuyen> _tram_thuoc_tuyens;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void Onid_tuyenChanging(int value);
        partial void Onid_tuyenChanged();
        partial void Onten_tuyen_diChanging(string value);
        partial void Onten_tuyen_diChanged();
        partial void Onten_tuyen_denChanging(string value);
        partial void Onten_tuyen_denChanged();
        #endregion

        public ds_tuyen()
        {
            this._tram_thuoc_tuyens = new EntitySet<tram_thuoc_tuyen>(new Action<tram_thuoc_tuyen>(this.attach_tram_thuoc_tuyens), new Action<tram_thuoc_tuyen>(this.detach_tram_thuoc_tuyens));
            OnCreated();
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_id_tuyen", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public int id_tuyen
        {
            get
            {
                return this._id_tuyen;
            }
            set
            {
                if ((this._id_tuyen != value))
                {
                    this.Onid_tuyenChanging(value);
                    this.SendPropertyChanging();
                    this._id_tuyen = value;
                    this.SendPropertyChanged("id_tuyen");
                    this.Onid_tuyenChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_ten_tuyen_di")]
        public string ten_tuyen_di
        {
            get
            {
                return this._ten_tuyen_di;
            }
            set
            {
                if ((this._ten_tuyen_di != value))
                {
                    this.Onten_tuyen_diChanging(value);
                    this.SendPropertyChanging();
                    this._ten_tuyen_di = value;
                    this.SendPropertyChanged("ten_tuyen_di");
                    this.Onten_tuyen_diChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_ten_tuyen_den")]
        public string ten_tuyen_den
        {
            get
            {
                return this._ten_tuyen_den;
            }
            set
            {
                if ((this._ten_tuyen_den != value))
                {
                    this.Onten_tuyen_denChanging(value);
                    this.SendPropertyChanging();
                    this._ten_tuyen_den = value;
                    this.SendPropertyChanged("ten_tuyen_den");
                    this.Onten_tuyen_denChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.AssociationAttribute( Storage = "_tram_thuoc_tuyens", ThisKey = "id_tuyen", OtherKey = "id_tuyen")]
        public EntitySet<tram_thuoc_tuyen> tram_thuoc_tuyens
        {
            get
            {
                return this._tram_thuoc_tuyens;
            }
            set
            {
                this._tram_thuoc_tuyens.Assign(value);
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void attach_tram_thuoc_tuyens(tram_thuoc_tuyen entity)
        {
            this.SendPropertyChanging();
            entity.ds_tuyen = this;
        }

        private void detach_tram_thuoc_tuyens(tram_thuoc_tuyen entity)
        {
            this.SendPropertyChanging();
            entity.ds_tuyen = null;
        }
    }

    [global::System.Data.Linq.Mapping.TableAttribute]
    public partial class tram_thuoc_tuyen : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _id_tuyen;

        private int _id_tram;

        private byte _tram_ve;

        private System.Nullable<int> _thu_tu_tram_dung;

        private EntityRef<ds_tram> _ds_tram;

        private EntityRef<ds_tuyen> _ds_tuyen;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void Onid_tuyenChanging(int value);
        partial void Onid_tuyenChanged();
        partial void Onid_tramChanging(int value);
        partial void Onid_tramChanged();
        partial void Ontram_veChanging(byte value);
        partial void Ontram_veChanged();
        partial void Onthu_tu_tram_dungChanging(System.Nullable<int> value);
        partial void Onthu_tu_tram_dungChanged();
        #endregion

        public tram_thuoc_tuyen()
        {
            this._ds_tram = default(EntityRef<ds_tram>);
            this._ds_tuyen = default(EntityRef<ds_tuyen>);
            OnCreated();
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_id_tuyen", DbType = "Int NOT NULL", IsPrimaryKey = true)]
        public int id_tuyen
        {
            get
            {
                return this._id_tuyen;
            }
            set
            {
                if ((this._id_tuyen != value))
                {
                    if (this._ds_tuyen.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.Onid_tuyenChanging(value);
                    this.SendPropertyChanging();
                    this._id_tuyen = value;
                    this.SendPropertyChanged("id_tuyen");
                    this.Onid_tuyenChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_id_tram", DbType = "Int NOT NULL", IsPrimaryKey = true)]
        public int id_tram
        {
            get
            {
                return this._id_tram;
            }
            set
            {
                if ((this._id_tram != value))
                {
                    if (this._ds_tram.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.Onid_tramChanging(value);
                    this.SendPropertyChanging();
                    this._id_tram = value;
                    this.SendPropertyChanged("id_tram");
                    this.Onid_tramChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_tram_ve", DbType = "TinyInt NOT NULL", IsPrimaryKey = true)]
        public byte tram_ve
        {
            get
            {
                return this._tram_ve;
            }
            set
            {
                if ((this._tram_ve != value))
                {
                    this.Ontram_veChanging(value);
                    this.SendPropertyChanging();
                    this._tram_ve = value;
                    this.SendPropertyChanged("tram_ve");
                    this.Ontram_veChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_thu_tu_tram_dung", DbType = "Int")]
        public System.Nullable<int> thu_tu_tram_dung
        {
            get
            {
                return this._thu_tu_tram_dung;
            }
            set
            {
                if ((this._thu_tu_tram_dung != value))
                {
                    this.Onthu_tu_tram_dungChanging(value);
                    this.SendPropertyChanging();
                    this._thu_tu_tram_dung = value;
                    this.SendPropertyChanged("thu_tu_tram_dung");
                    this.Onthu_tu_tram_dungChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.AssociationAttribute(Storage = "_ds_tram", ThisKey = "id_tram", OtherKey = "id_tram", IsForeignKey = true)]
        public ds_tram ds_tram
        {
            get
            {
                return this._ds_tram.Entity;
            }
            set
            {
                ds_tram previousValue = this._ds_tram.Entity;
                if (((previousValue != value)
                            || (this._ds_tram.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._ds_tram.Entity = null;
                        previousValue.tram_thuoc_tuyens.Remove(this);
                    }
                    this._ds_tram.Entity = value;
                    if ((value != null))
                    {
                        value.tram_thuoc_tuyens.Add(this);
                        this._id_tram = value.id_tram;
                    }
                    else
                    {
                        this._id_tram = default(int);
                    }
                    this.SendPropertyChanged("ds_tram");
                }
            }
        }

        [global::System.Data.Linq.Mapping.AssociationAttribute( Storage = "_ds_tuyen", ThisKey = "id_tuyen", OtherKey = "id_tuyen", IsForeignKey = true)]
        public ds_tuyen ds_tuyen
        {
            get
            {
                return this._ds_tuyen.Entity;
            }
            set
            {
                ds_tuyen previousValue = this._ds_tuyen.Entity;
                if (((previousValue != value)
                            || (this._ds_tuyen.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._ds_tuyen.Entity = null;
                        previousValue.tram_thuoc_tuyens.Remove(this);
                    }
                    this._ds_tuyen.Entity = value;
                    if ((value != null))
                    {
                        value.tram_thuoc_tuyens.Add(this);
                        this._id_tuyen = value.id_tuyen;
                    }
                    else
                    {
                        this._id_tuyen = default(int);
                    }
                    this.SendPropertyChanged("ds_tuyen");
                }
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
